/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.BorderLayout;
import java.awt.Container;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.query.JRHibernateQueryExecuterFactory;
import net.sf.jasperreports.swing.JRViewer;
import org.hibernate.Session;
import util.NewHibernateUtil;

/**
 *
 * @author TUYETQUAN
 */
public class Report_LoaiSP extends javax.swing.JInternalFrame {

    /**
     * Creates new form Report_LoaiSP
     */
    public Report_LoaiSP() {
         super("Thống kê loại sản phẩm",true,true,true,true);
        initComponents();
         setBounds(10,10,600,500);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
public Report_LoaiSP(String filename) throws JRException{
        this(filename,null);
    }
   public Report_LoaiSP(String filename, HashMap parameter) throws JRException{
       this();
       try{
//           Class.forName("org.postgresql.Driver");
//            Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/quan_ly_chuoi_cua_hang_ban_quan_ao", "postgres", "077");
//         //  Session session = NewHibernateUtil.getSessionFactory().openSession();
//            /*
//             * (Here the parameter file should be in .jasper extension i.e., the
//             * compiled report)
//             */
//            JasperPrint print = JasperFillManager.fillReport(filename, parameter,con);
//            JRViewer viewer = new JRViewer(print);
//            Container c = getContentPane();
//            c.setLayout(new BorderLayout());
//            c.add(viewer);
//       }catch(ClassNotFoundException cnfe){
//            cnfe.printStackTrace();
//       } catch (SQLException sqle) {
//            sqle.printStackTrace();
//       } catch (JRException jre) {
//            jre.printStackTrace();
//       }
            parameter = new HashMap();
            Session session = NewHibernateUtil.getSessionFactory().openSession();
            parameter.put(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION, session);
            JasperPrint print = JasperFillManager.fillReport(filename, parameter);
            JRViewer viewer = new JRViewer(print);
            Container c = getContentPane();
            c.setLayout(new BorderLayout());
            c.add(viewer);
            session.close();
            } catch (Exception jre) {
            jre.printStackTrace();
            }
   }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 394, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 278, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
